/**
 * Copyright 2007-2010 非也
 * All rights reserved. 
 * 
 * This library is free software; you can redistribute it and/or modify it under the
 * terms of the GNU Lesser General Public License v3 as published by the Free Software
 * Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License along
 * with this library; if not, see http://www.gnu.org/licenses/lgpl.html.
 *
 */
package org.fireflow2.designer.eclipse.policies;

import org.eclipse.draw2d.IFigure;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.gef.Request;
import org.eclipse.gef.RequestConstants;
import org.eclipse.gef.editpolicies.SelectionEditPolicy;
import org.eclipse.gef.requests.CreateRequest;
import org.eclipse.swt.graphics.Color;
import org.fireflow.pdl.fpdl20.diagram.Fpdl20DiagramElement;
import org.fireflow2.designer.eclipse.palette.DiagramElementSubType;
import org.fireflow2.designer.eclipse.util.Util4Eclipse;

/**
 *
 * @author 非也 nychen2000@163.com
 * Fire Workflow 官方网站：www.firesoa.com 或者 www.fireflow.org
 *
 */
public class WorkflowNodeHighlightEditPolicy extends CommonResizableEditPolicy {

	private Color revertColor;

	public void eraseTargetFeedback(Request request) {
		this.hideSelection();
//		if (revertColor != null) {
//			setContainerBackground(revertColor);
//			revertColor = null;
//		}
	}

//	private Color getContainerBackground() {
//		return getContainerFigure().getBackgroundColor();
//	}

//	private IFigure getContainerFigure() {
//		IFigure figure = ((GraphicalEditPart) getHost()).getContentPane();
//		return figure;
//	}

	public EditPart getTargetEditPart(Request request) {

		return request.getType().equals(RequestConstants.REQ_SELECTION_HOVER) ? getHost()
				: null;
	}

//	private void setContainerBackground(Color c) {
//		getContainerFigure().setBackgroundColor(c);
//	}

//	protected void showHighlight() {
//
//		if (revertColor == null) {
//			revertColor = getContainerBackground();
//			setContainerBackground(Util4Eclipse.colorStr2ColorObj("#FFF5EE"));
//		}
//	}

	public void showTargetFeedback(Request request) {
		if (request.getType().equals(RequestConstants.REQ_CREATE)){
			
			CreateRequest createRequest = (CreateRequest)request;
			Object newObj = createRequest.getNewObject();
			Object newObjType = createRequest.getNewObjectType();
			
			if (Fpdl20DiagramElement.START_NODE.equals(newObj)
					&& (DiagramElementSubType.START_CATCH_COMPENSATION_START.equals(newObjType)
						||DiagramElementSubType.START_CATCH_FAULT_START.equals(newObjType))){

				this.showSelection();
			}
		}else if (request.getType().equals(	RequestConstants.REQ_CONNECTION_START)
				|| request.getType()
					.equals(RequestConstants.REQ_CONNECTION_END)){
			this.showSelection();
			
		}
	}

	/* (non-Javadoc)
	 * @see org.eclipse.gef.editpolicies.SelectionEditPolicy#hideSelection()
	 */


}
